﻿@model CMS.Common.Helpers.PagedData<CMSApplication.Areas.Administration.Models.UserModel>

<script>
    $(document).ready(function () {
        $(".page-number").on("click", function () {
            var keys = $("#user-search-key").val();
            var roleId = $("#RolesID").val();
            var page = parseInt($(this).html());
            $.get("/UserManagement/List?keys=" + keys + "&roleId=" + roleId + "&page=" + page, function (data) {
                $(".listuser").html("");
                $(".listuser").html(data);
            });
        });

        $("a.delete").click(function () {
            var item_id = $(this).closest('tr').find('.Spanid').html();
            if (confirm("Bạn chắc chắn muốn xóa nhân viên: Mã = " + item_id + "?")) {
                var keys = $("#user-search-key").val();
                var roleId = $("#RolesID").val();
                var page = parseInt($(".page-number-Current").html());
                $.get("/UserManagement/deleteUser?id=" + item_id, function () {
                    $.get("/UserManagement/List?keys=" + keys + "&roleId=" + roleId + "&page=" + page, function (data) {
                        $(".listuser").html("");
                        $(".listuser").html(data);
                    });
                });
            }
        });
    });
</script>

@if (Model.Data.Count() > 0)
{
    <table class="table dataTable" style="width: 100%">
        <thead>
            <th style="text-align:center;">Mã</th>
            <th>Họ & Tên</th>
            <th>Điện thoại</th>
            <th>Địa chỉ</th>
            <th>Loại</th>
            <th style="text-align:center;">Trạng thái</th>
            <th style="text-align:center;">Ngày tạo</th>
            <th style="text-align:center;">Thao tác</th>
        </thead>
        <tbody>
            @foreach (var item in Model.Data)
            {
                <tr user-mail="@item.Email">
                    <td style="text-align:center;">
                        <span class="Spanid">@item.Id</span>
                    </td>
                    <td>
                        <span>@item.FullName </span>
                    </td>
                    <td>
                        <span>@item.Phone</span>
                    </td>
                    <td>
                        <span>@item.Address</span>
                    </td>
                    <td>
                        <span >@item.RoleName </span>
                    </td>
                    <td style="text-align:center;">
                        @Html.CheckBox("Acitve", item.Status, new { disabled="disabled"})
                    </td>
                    <td style="text-align:center;">
                        <span>@string.Format("{0:dd/MM/yyyy}", item.DataCreate) </span>
                    </td>
                    <td style="text-align:center;">
                        <a href="@Url.Action("Edit", "UserManagement", new { id = item.Id })" class="icon-pencil" title="Chỉnh sửa » @item.Id"></a>
                        <a href="javascript:void(0)" class="icon-trash delete" title="Xóa bỏ » @item.Id"></a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div class="dataTables_paginate paging_full_numbers" id="tSortable_2_paginate">
        <span>
            @for (int m = 1; m <= Model.NumberOfPages; m++)
            {
                if (m == Model.CurrentPage)
                {
                     <a href="javascript:void(0);" tabindex="0" class="paginate_active page-number-Current">@m</a>
                }
                else
                {
                    <a class="paginate_button page-number" href="javascript:void(0);" tabindex="0">@m</a>
                }
            }
        </span>
    </div>
}
else
{
    <h2>
        Không có dữ liệu.
    </h2>
}

<div class="dialog" id="b_popup_4" style="display: none;" title="Send Email To">    
     @using (Html.BeginForm("SendEmail", "UserManagement", FormMethod.Post, new { @id = "form-upload", enctype = "multipart/form-data" }))
     {                            
        <div class="block">
            <p>   
                <input type="text" name="email" id="email-input" readonly="true"/>                 
            </p>
            <p>   
                <input type="text" name="subject" placeholder="Subject"/>                 
            </p>
            <p>   
                <textarea rows="3" name="body"></textarea>              
            </p>
        </div>
        }
    </div>

<script type="text/javascript">
    $(document).ready(function () {
        $("#b_popup_4").dialog({
            autoOpen: false,
            modal: true,
            width: 400,
            buttons: {
                "Ok": function () {
                    $("#form-upload").submit();
                },
                Cancel: function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".popup_4").click(function () {
            $("#email-input").val($(this).parents("tr").attr("user-mail"));
            $("#b_popup_4").dialog('open')
        });
    })

</script>
